﻿@typeparam TItem
@inherits BaseDataGridComponent
<TableRow Class="@Class" Style="@Style" Background="@Background" Color="@Color">

    @foreach ( var column in Columns )
    {
        @if ( column.ColumnType == DataGridColumnType.Command )
        {
            @if ( ParentDataGrid.IsCommandVisible )
            {
                <TableRowCell></TableRowCell>
            }
        }
        else if ( column.ColumnType == DataGridColumnType.MultiSelect )
        {
            @if ( ParentDataGrid.MultiSelect )
            {
                <TableRowCell></TableRowCell>
            }
        }
        else
        {
            <TableRowCell Class="@column.GroupCellClass" Style="@column.BuildGroupCellStyle()" TextAlignment="@column.TextAlignment" VerticalAlignment="@column.VerticalAlignment" Display="@column.Display">
                @{
                    var aggregateColumn = Aggregates.FirstOrDefault( x => x.Field == column.Field );

                    if ( aggregateColumn != null )
                    {
                        var aggregateValue = Calculate( aggregateColumn, column );

                        @if ( aggregateColumn.DisplayTemplate != null )
                        {
                            @aggregateColumn.DisplayTemplate( new( column.Field, aggregateValue ) )
                        }
                        else
                        {
                            @aggregateColumn.FormatDisplayValue( aggregateValue );
                        }
                    }
                }
            </TableRowCell>
        }
    }
</TableRow>